﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using AutoR.Messages;
using AutoR.Models;
using AutoR.Services;
using LiteDB;
using Xamarin.Forms;

namespace AutoR.Helpers
{
	// Token: 0x02000213 RID: 531
	public static class Extensions
	{
		// Token: 0x06000C9E RID: 3230 RVA: 0x0006EF4C File Offset: 0x0006D14C
		public static void UpdateShipInWar(int node, DealNode dn)
		{
			if (dn.warReport != null)
			{
				int si2;
				int si;
				for (si = 0; si < dn.warReport.selfShips.Count; si = si2 + 1)
				{
					ShipInWar ship = dn.warReport.selfShips[si];
					StatDealNode statDealNode = new StatDealNode
					{
						Node = node
					};
					IEnumerable<float> source = (from i in dn.warReport.AttackParams
					where i.attackSide == AttackSide.Self && i.fromIndex == si
					select i).SelectMany((AttackParam i) => i.damage);
					statDealNode.AttackDamge = source.Sum();
					statDealNode.AttackAverage = new double?((double)(from i in source
					where i > 0f
					select i).DefaultIfEmpty<float>().Average());
					statDealNode.AttackNum = source.Count<float>();
					statDealNode.AttackMiss = source.Count((float i) => i == 0f);
					IEnumerable<float> source2 = from i in dn.warReport.AttackParams
					where i.attackSide == AttackSide.Enemy && i.targetIndex.Contains(si)
					select i.damage[i.targetIndex.IndexOf(si)];
					statDealNode.BeAttackDamge = source2.Sum();
					statDealNode.BeAttackNum = source2.Count<float>();
					statDealNode.Dodge = source2.Count((float i) => i == 0f);
					if (Runtime.Statistics.GetCollection<StatDealNode>().Count((StatDealNode i) => i.shipid == ship.id && i.Node == node) != 0)
					{
						StatDealNode statDealNode2 = Runtime.Statistics.GetCollection<StatDealNode>().FindOne((StatDealNode i) => i.shipid == ship.id && i.Node == node);
						statDealNode2.AttackDamge += statDealNode.AttackDamge;
						statDealNode2.AttackNum += statDealNode.AttackNum;
						statDealNode2.AttackMiss += statDealNode.AttackMiss;
						statDealNode2.AttackAverage = new double?[]
						{
							statDealNode2.AttackAverage,
							statDealNode.AttackAverage
						}.Where(delegate(double? i)
						{
							double? num = i;
							double num2 = 0.0;
							return num.GetValueOrDefault() > num2 & num != null;
						}).DefaultIfEmpty<double?>().Average();
						statDealNode2.BeAttackDamge += statDealNode.BeAttackDamge;
						statDealNode2.BeAttackNum += statDealNode.BeAttackNum;
						statDealNode2.Dodge += statDealNode.Dodge;
						Runtime.Statistics.GetCollection<StatDealNode>().Update(statDealNode2);
					}
					else
					{
						Runtime.Statistics.GetCollection<StatDealNode>().Upsert(new StatDealNode
						{
							shipid = ship.id,
							Node = node,
							title = ship.title
						});
					}
					si2 = si;
				}
			}
		}

		// Token: 0x06000C9F RID: 3231 RVA: 0x0006F440 File Offset: 0x0006D640
		public static void UpdateStatFoundEnemy(int node, FoundEnemyVO fo)
		{
			if (fo.enemyShips != null)
			{
				string fs = string.Join(",", from q in fo.enemyShips
				select q.type.ToName());
				if (Runtime.Statistics.GetCollection<StatFoundEnemy>().Count((StatFoundEnemy i) => i.Node == node && i.Fleet == fs) != 0)
				{
					StatFoundEnemy statFoundEnemy = Runtime.Statistics.GetCollection<StatFoundEnemy>().FindOne((StatFoundEnemy i) => i.Node == node && i.Fleet == fs);
					statFoundEnemy.Count++;
					Runtime.Statistics.GetCollection<StatFoundEnemy>().Update(statFoundEnemy);
					return;
				}
				LiteCollection<StatFoundEnemy> collection = Runtime.Statistics.GetCollection<StatFoundEnemy>();
				StatFoundEnemy statFoundEnemy2 = new StatFoundEnemy();
				statFoundEnemy2.Node = node;
				PVENode pvenode = Runtime.Configs.PVEConfig.PVENode.FirstOrDefault((PVENode s) => s.id == node);
				statFoundEnemy2.Flag = ((pvenode != null) ? pvenode.flag : null);
				statFoundEnemy2.Fleet = fs;
				statFoundEnemy2.Count = 1;
				collection.Upsert(statFoundEnemy2);
			}
		}

		// Token: 0x06000CA0 RID: 3232 RVA: 0x0006F6B4 File Offset: 0x0006D8B4
		public static void UpdateStatSkipWar(int node, bool isSuccess)
		{
			if (Runtime.Statistics.GetCollection<StatSkipWar>().Count((StatSkipWar i) => i.Node == node) != 0)
			{
				StatSkipWar statSkipWar = Runtime.Statistics.GetCollection<StatSkipWar>().FindOne((StatSkipWar i) => i.Node == node);
				if (isSuccess)
				{
					statSkipWar.Success++;
				}
				else
				{
					statSkipWar.UnSuccess++;
				}
				Runtime.Statistics.GetCollection<StatSkipWar>().Update(statSkipWar);
				return;
			}
			Runtime.Statistics.GetCollection<StatSkipWar>().Upsert(new StatSkipWar
			{
				Node = node,
				Success = (isSuccess ? 1 : 0),
				UnSuccess = (isSuccess ? 0 : 1)
			});
		}

		// Token: 0x06000CA1 RID: 3233 RVA: 0x0006F81C File Offset: 0x0006DA1C
		public static void UpdateStatBuild(int shipCid)
		{
			if (Runtime.Statistics.GetCollection<StatBuild>().Count((StatBuild i) => i.ShipCid == shipCid) != 0)
			{
				StatBuild statBuild = Runtime.Statistics.GetCollection<StatBuild>().FindOne((StatBuild i) => i.ShipCid == shipCid);
				statBuild.Count++;
				Runtime.Statistics.GetCollection<StatBuild>().Update(statBuild);
				return;
			}
			Runtime.Statistics.GetCollection<StatBuild>().Upsert(new StatBuild
			{
				ShipCid = shipCid,
				Count = 1
			});
		}

		// Token: 0x06000CA2 RID: 3234 RVA: 0x0006F95C File Offset: 0x0006DB5C
		public static void UpdateStatEquipment(int cid)
		{
			if (Runtime.Statistics.GetCollection<StatEquipment>().Count((StatEquipment i) => i.EquipmentCid == cid) != 0)
			{
				StatEquipment statEquipment = Runtime.Statistics.GetCollection<StatEquipment>().FindOne((StatEquipment i) => i.EquipmentCid == cid);
				statEquipment.Count++;
				Runtime.Statistics.GetCollection<StatEquipment>().Update(statEquipment);
				return;
			}
			Runtime.Statistics.GetCollection<StatEquipment>().Upsert(new StatEquipment
			{
				EquipmentCid = cid,
				Count = 1
			});
		}

		// Token: 0x06000CA3 RID: 3235 RVA: 0x0006FA9C File Offset: 0x0006DC9C
		public static void UpdateStatNewShip(int node, int shipCid)
		{
			if (Runtime.Statistics.GetCollection<StatNewShip>().Count((StatNewShip i) => i.Node == node && i.ShipCid == shipCid) != 0)
			{
				StatNewShip statNewShip = Runtime.Statistics.GetCollection<StatNewShip>().FindOne((StatNewShip i) => i.Node == node && i.ShipCid == shipCid);
				statNewShip.Count++;
				Runtime.Statistics.GetCollection<StatNewShip>().Update(statNewShip);
				return;
			}
			LiteCollection<StatNewShip> collection = Runtime.Statistics.GetCollection<StatNewShip>();
			StatNewShip statNewShip2 = new StatNewShip();
			statNewShip2.Node = node;
			PVENode pvenode = Runtime.Configs.PVEConfig.PVENode.FirstOrDefault((PVENode s) => s.id == node);
			statNewShip2.Flag = ((pvenode != null) ? pvenode.flag : null);
			statNewShip2.ShipCid = shipCid;
			statNewShip2.Count = 1;
			collection.Upsert(statNewShip2);
		}

		// Token: 0x06000CA4 RID: 3236 RVA: 0x0006FCA0 File Offset: 0x0006DEA0
		public static async Task GenerateFleet(ObservableCollection<RuleFleet> ruleFleet, int fleetID, bool rndPos = false)
		{
			Extensions.<>c__DisplayClass7_0 CS$<>8__locals1 = new Extensions.<>c__DisplayClass7_0();
			CS$<>8__locals1.fleetID = fleetID;
			CS$<>8__locals1.fleet = new Extensions.TargetFleet[6];
			CS$<>8__locals1.rlist = new Queue<Extensions.TargetFleet>();
			Extensions.<>c__DisplayClass7_0 CS$<>8__locals2 = CS$<>8__locals1;
			RankListDestroy destroyRank = Runtime.Game.User.DestroyRank;
			List<LBDataDestroy> list;
			if (destroyRank == null)
			{
				list = null;
			}
			else
			{
				list = (from i in destroyRank.list
				where i.uid == Runtime.Game.User.uid
				select i).ToList<LBDataDestroy>();
			}
			CS$<>8__locals2.deslist = (list ?? new List<LBDataDestroy>());
			using (IEnumerator<RuleFleet> enumerator = ruleFleet.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					RuleFleet rule = enumerator.Current;
					if (rule.TypeB)
					{
						List<UserShip> list2 = (from i in Runtime.Game.UserShip
						where rule.ShipType.Contains(i.Type) && i.level >= rule.MinLv && i.level <= rule.MaxLv && i.fleetId < 5
						select i).ToList<UserShip>();
						if (rule.IsLock)
						{
							list2 = (from i in list2
							where i.isLocked
							select i).ToList<UserShip>();
						}
						if (Runtime.Game.GlobalConfig.Rank)
						{
							IEnumerable<UserShip> source = list2;
							Func<UserShip, bool> predicate;
							if ((predicate = CS$<>8__locals1.<>9__6) == null)
							{
								predicate = (CS$<>8__locals1.<>9__6 = ((UserShip i) => !CS$<>8__locals1.deslist.Any((LBDataDestroy d) => d.shipLevel == i.level && d.shipCid == i.shipCid)));
							}
							list2 = source.Where(predicate).ToList<UserShip>();
						}
						if (rndPos)
						{
							List<UserShip> list3;
							if (!rule.LvOrder)
							{
								list3 = (from i in list2
								orderby i.isLocked descending, i.status, i.BrokenType, i.level descending, new Random().Next()
								select i).ToList<UserShip>();
							}
							else
							{
								list3 = (from i in list2
								orderby i.isLocked descending, i.status, i.BrokenType, i.level, new Random().Next()
								select i).ToList<UserShip>();
							}
							list2 = list3;
						}
						else
						{
							List<UserShip> list4;
							if (!rule.LvOrder)
							{
								list4 = (from i in list2
								orderby i.isLocked descending, i.status, i.BrokenType, i.level descending, i.id
								select i).ToList<UserShip>();
							}
							else
							{
								list4 = (from i in list2
								orderby i.isLocked descending, i.status, i.BrokenType, i.level, i.id
								select i).ToList<UserShip>();
							}
							list2 = list4;
						}
						int num = 0;
						using (List<UserShip>.Enumerator enumerator2 = list2.GetEnumerator())
						{
							while (enumerator2.MoveNext())
							{
								UserShip ss = enumerator2.Current;
								if (CS$<>8__locals1.fleet.All(delegate(Extensions.TargetFleet f)
								{
									UserShip userShip3 = Runtime.Game.UserShip.SingleOrDefault(delegate(UserShip u)
									{
										int id = u.id;
										Extensions.TargetFleet f = f;
										int? num3 = (f != null) ? new int?(f.ID) : null;
										return id == num3.GetValueOrDefault() & num3 != null;
									});
									int? num2 = (userShip3 != null) ? new int?(userShip3.evoCid) : null;
									int evoCid = ss.evoCid;
									return !(num2.GetValueOrDefault() == evoCid & num2 != null);
								}) && CS$<>8__locals1.rlist.All(delegate(Extensions.TargetFleet f)
								{
									UserShip userShip3 = Runtime.Game.UserShip.SingleOrDefault(delegate(UserShip u)
									{
										int id = u.id;
										Extensions.TargetFleet f = f;
										int? num3 = (f != null) ? new int?(f.ID) : null;
										return id == num3.GetValueOrDefault() & num3 != null;
									});
									int? num2 = (userShip3 != null) ? new int?(userShip3.evoCid) : null;
									int evoCid = ss.evoCid;
									return !(num2.GetValueOrDefault() == evoCid & num2 != null);
								}))
								{
									CS$<>8__locals1.rlist.Enqueue(new Extensions.TargetFleet
									{
										ID = ss.id,
										RuleFleet = rule
									});
									num++;
								}
								if (num == rule.Number)
								{
									break;
								}
							}
							continue;
						}
					}
					if (rule.TypeC)
					{
						List<UserShip> list5 = (from i in Runtime.Game.UserShip
						where i.Name.Contains(rule.SelectName) && i.level >= rule.MinLv && i.level <= rule.MaxLv && i.fleetId < 5 && CS$<>8__locals1.fleet.All(delegate(Extensions.TargetFleet f)
						{
							int? num2;
							if (f == null)
							{
								num2 = null;
							}
							else
							{
								UserShip userShip3 = f.ID.ToUserShip();
								num2 = ((userShip3 != null) ? new int?(userShip3.evoCid) : null);
							}
							int? num3 = num2;
							int evoCid = i.evoCid;
							return !(num3.GetValueOrDefault() == evoCid & num3 != null);
						}) && CS$<>8__locals1.rlist.All(delegate(Extensions.TargetFleet f)
						{
							UserShip userShip3 = f.ID.ToUserShip();
							int? num2 = (userShip3 != null) ? new int?(userShip3.evoCid) : null;
							int evoCid = i.evoCid;
							return !(num2.GetValueOrDefault() == evoCid & num2 != null);
						})
						select i).ToList<UserShip>();
						if (rule.IsLock)
						{
							list5 = (from i in list5
							where i.isLocked
							select i).ToList<UserShip>();
						}
						if (Runtime.Game.GlobalConfig.Rank)
						{
							IEnumerable<UserShip> source2 = list5;
							Func<UserShip, bool> predicate2;
							if ((predicate2 = CS$<>8__locals1.<>9__34) == null)
							{
								predicate2 = (CS$<>8__locals1.<>9__34 = ((UserShip i) => !CS$<>8__locals1.deslist.Any((LBDataDestroy d) => d.shipLevel == i.level && d.shipCid == i.shipCid)));
							}
							list5 = source2.Where(predicate2).ToList<UserShip>();
						}
						if (rndPos)
						{
							List<UserShip> list6;
							if (!rule.LvOrder)
							{
								list6 = (from i in list5
								orderby i.isLocked descending, i.status, i.BrokenType, i.level descending, new Random().Next()
								select i).ToList<UserShip>();
							}
							else
							{
								list6 = (from i in list5
								orderby i.isLocked descending, i.status, i.BrokenType, i.level, new Random().Next()
								select i).ToList<UserShip>();
							}
							list5 = list6;
						}
						else
						{
							List<UserShip> list7;
							if (!rule.LvOrder)
							{
								list7 = (from i in list5
								orderby i.isLocked descending, i.status, i.BrokenType, i.level descending, i.id
								select i).ToList<UserShip>();
							}
							else
							{
								list7 = (from i in list5
								orderby i.isLocked descending, i.status, i.BrokenType, i.level, i.id
								select i).ToList<UserShip>();
							}
							list5 = list7;
						}
						UserShip userShip = list5.FirstOrDefault<UserShip>();
						if (userShip != null)
						{
							CS$<>8__locals1.fleet[rule.Position] = new Extensions.TargetFleet
							{
								ID = userShip.id,
								RuleFleet = rule
							};
						}
					}
					else
					{
						IEnumerable<UserShip> enumerable = rule.ShipID.ToUserShipList();
						if (rule.MaxLv > 0)
						{
							enumerable = from i in enumerable
							where i.fleetId < 5 && i.level <= rule.MaxLv && CS$<>8__locals1.fleet.All(delegate(Extensions.TargetFleet f)
							{
								int? num2;
								if (f == null)
								{
									num2 = null;
								}
								else
								{
									UserShip userShip3 = f.ID.ToUserShip();
									num2 = ((userShip3 != null) ? new int?(userShip3.evoCid) : null);
								}
								int? num3 = num2;
								int evoCid = i.evoCid;
								return !(num3.GetValueOrDefault() == evoCid & num3 != null);
							}) && CS$<>8__locals1.rlist.All(delegate(Extensions.TargetFleet f)
							{
								UserShip userShip3 = f.ID.ToUserShip();
								int? num2 = (userShip3 != null) ? new int?(userShip3.evoCid) : null;
								int evoCid = i.evoCid;
								return !(num2.GetValueOrDefault() == evoCid & num2 != null);
							})
							select i;
						}
						else
						{
							IEnumerable<UserShip> source3 = enumerable;
							Func<UserShip, bool> predicate3;
							if ((predicate3 = CS$<>8__locals1.<>9__59) == null)
							{
								predicate3 = (CS$<>8__locals1.<>9__59 = ((UserShip i) => i.fleetId < 5 && CS$<>8__locals1.fleet.All(delegate(Extensions.TargetFleet f)
								{
									int? num2;
									if (f == null)
									{
										num2 = null;
									}
									else
									{
										UserShip userShip3 = f.ID.ToUserShip();
										num2 = ((userShip3 != null) ? new int?(userShip3.evoCid) : null);
									}
									int? num3 = num2;
									int evoCid = i.evoCid;
									return !(num3.GetValueOrDefault() == evoCid & num3 != null);
								}) && CS$<>8__locals1.rlist.All(delegate(Extensions.TargetFleet f)
								{
									UserShip userShip3 = f.ID.ToUserShip();
									int? num2 = (userShip3 != null) ? new int?(userShip3.evoCid) : null;
									int evoCid = i.evoCid;
									return !(num2.GetValueOrDefault() == evoCid & num2 != null);
								})));
							}
							enumerable = source3.Where(predicate3);
						}
						if (Runtime.Game.GlobalConfig.Rank)
						{
							IEnumerable<UserShip> source4 = enumerable;
							Func<UserShip, bool> predicate4;
							if ((predicate4 = CS$<>8__locals1.<>9__60) == null)
							{
								predicate4 = (CS$<>8__locals1.<>9__60 = ((UserShip i) => !CS$<>8__locals1.deslist.Any((LBDataDestroy d) => d.shipLevel == i.level && d.shipCid == i.shipCid)));
							}
							enumerable = source4.Where(predicate4);
						}
						if (rndPos)
						{
							enumerable = from i in enumerable
							orderby i.status, i.BrokenType, new Random().Next()
							select i;
						}
						else
						{
							enumerable = from i in enumerable
							orderby i.status, i.BrokenType
							select i;
						}
						UserShip userShip2 = enumerable.FirstOrDefault<UserShip>();
						if (userShip2 != null)
						{
							CS$<>8__locals1.fleet[rule.Position] = new Extensions.TargetFleet
							{
								ID = userShip2.id,
								RuleFleet = rule
							};
						}
					}
				}
			}
			for (int j = 0; j < CS$<>8__locals1.fleet.Length; j++)
			{
				if (CS$<>8__locals1.fleet[j] == null && CS$<>8__locals1.rlist.Count > 0)
				{
					CS$<>8__locals1.fleet[j] = CS$<>8__locals1.rlist.Dequeue();
				}
			}
			Extensions.<>c__DisplayClass7_11 CS$<>8__locals5 = new Extensions.<>c__DisplayClass7_11();
			CS$<>8__locals5.CS$<>8__locals2 = CS$<>8__locals1;
			CS$<>8__locals5.i = 0;
			while (CS$<>8__locals5.i < Runtime.Game.Fleet[CS$<>8__locals5.CS$<>8__locals2.fleetID].ships.Count)
			{
				if (CS$<>8__locals5.CS$<>8__locals2.fleet.All(delegate(Extensions.TargetFleet f)
				{
					int? num2 = (f != null) ? new int?(f.ID) : null;
					int num3 = Runtime.Game.Fleet[CS$<>8__locals5.CS$<>8__locals2.fleetID].ships[CS$<>8__locals5.i];
					return !(num2.GetValueOrDefault() == num3 & num2 != null);
				}) && CS$<>8__locals5.CS$<>8__locals2.fleet[CS$<>8__locals5.i] != null && CS$<>8__locals5.CS$<>8__locals2.fleet[CS$<>8__locals5.i].RuleFleet.IsRemoveEquip)
				{
					UserShip ship = Runtime.Game.Fleet[CS$<>8__locals5.CS$<>8__locals2.fleetID].ships[CS$<>8__locals5.i].ToUserShip();
					for (int k = 0; k < ship.Equipment.Count; k++)
					{
						if (ship.Equipment[k].cid != -1)
						{
							await Runtime.Game.RemoveEquipment(ship.id, k);
						}
					}
					MessagingCenter.Send<LogMessage>(new LogMessage("[换装]扒光" + ship.Name + "装备完成"), "Log");
					ship = null;
				}
				CS$<>8__locals5.i++;
			}
			CS$<>8__locals5 = null;
			List<Extensions.TargetFleet> cl = (from i in CS$<>8__locals1.fleet
			where i != null && !Runtime.Game.Fleet[CS$<>8__locals1.fleetID].ships.Contains(i.ID)
			select i).ToList<Extensions.TargetFleet>();
			int[] result = (from i in CS$<>8__locals1.fleet
			where i != null
			select i.ID).ToArray<int>();
			if (result.Length != 0 && !result.SequenceEqual(Runtime.Game.Fleet[CS$<>8__locals1.fleetID].ships))
			{
				MessagingCenter.Send<LogMessage>(new LogMessage("[详细]开始更换舰队"), "FullLog");
				List<UserShip> ships = (from i in result.ToUserShipList()
				where i.fleetId > 0 && i.fleetId != CS$<>8__locals1.fleetID + 1
				select i).ToList<UserShip>();
				await Runtime.Game.RemoveBoat(ships);
				await Runtime.Game.InstantFleet(CS$<>8__locals1.fleetID + 1, result);
				MessagingCenter.Send<LogMessage>(new LogMessage(string.Format("[换船]{0}舰队更换为:{1}", CS$<>8__locals1.fleetID + 1, string.Join(", ", from i in result.ToUserShipList()
				select i.Name))), "Log");
			}
			foreach (Extensions.TargetFleet tf in cl)
			{
				UserShip ship = tf.ID.ToUserShip();
				if (tf.RuleFleet.Equipment1 != 0 && ship.Equipment.ElementAt(0).cid != tf.RuleFleet.Equipment1)
				{
					await Extensions.RemoveExistEquip(tf, tf.RuleFleet.Equipment1, CS$<>8__locals1.fleetID);
					await Runtime.Game.ChangeEquipment(tf.ID, tf.RuleFleet.Equipment1, 0);
					MessagingCenter.Send<LogMessage>(new LogMessage("[换装]更换" + tf.ID.ToUserShip().Name + "装备:" + tf.RuleFleet.Equipment1.ToEquipName()), "Log");
				}
				if (tf.RuleFleet.Equipment2 != 0 && ship.Equipment.Count > 1 && ship.Equipment.ElementAt(1).cid != tf.RuleFleet.Equipment2)
				{
					await Extensions.RemoveExistEquip(tf, tf.RuleFleet.Equipment2, CS$<>8__locals1.fleetID);
					await Runtime.Game.ChangeEquipment(tf.ID, tf.RuleFleet.Equipment2, 1);
					MessagingCenter.Send<LogMessage>(new LogMessage("[换装]更换" + tf.ID.ToUserShip().Name + "装备:" + tf.RuleFleet.Equipment2.ToEquipName()), "Log");
				}
				if (tf.RuleFleet.Equipment3 != 0 && ship.Equipment.Count > 2 && ship.Equipment.ElementAt(2).cid != tf.RuleFleet.Equipment3)
				{
					await Extensions.RemoveExistEquip(tf, tf.RuleFleet.Equipment3, CS$<>8__locals1.fleetID);
					await Runtime.Game.ChangeEquipment(tf.ID, tf.RuleFleet.Equipment3, 2);
					MessagingCenter.Send<LogMessage>(new LogMessage("[换装]更换" + tf.ID.ToUserShip().Name + "装备:" + tf.RuleFleet.Equipment3.ToEquipName()), "Log");
				}
				if (tf.RuleFleet.Equipment4 != 0 && ship.Equipment.Count > 3 && ship.Equipment.ElementAt(3).cid != tf.RuleFleet.Equipment4)
				{
					await Extensions.RemoveExistEquip(tf, tf.RuleFleet.Equipment4, CS$<>8__locals1.fleetID);
					await Runtime.Game.ChangeEquipment(tf.ID, tf.RuleFleet.Equipment4, 3);
					MessagingCenter.Send<LogMessage>(new LogMessage("[换装]更换" + tf.ID.ToUserShip().Name + "装备:" + tf.RuleFleet.Equipment4.ToEquipName()), "Log");
				}
				ship = null;
				tf = null;
			}
			List<Extensions.TargetFleet>.Enumerator enumerator3 = default(List<Extensions.TargetFleet>.Enumerator);
		}

		// Token: 0x06000CA5 RID: 3237 RVA: 0x0006FCF8 File Offset: 0x0006DEF8
		private static async Task RemoveExistEquip(Extensions.TargetFleet tf, int equip, int fid)
		{
			if (tf.RuleFleet.Equipped)
			{
				if ((from i in Runtime.Game.Equipments
				where i.num > 0
				select i).All((UserEquipment i) => i.equipmentCid != equip))
				{
					var source = (from i in Runtime.Game.UserShip
					from s in i.Equipment
					select new
					{
						s.cid,
						i.id,
						i.level,
						i.fleetId
					} into i
					where i.cid == equip
					select i).OrderBy(delegate(i)
					{
						if (i.fleetId != fid + 1)
						{
							return i.fleetId;
						}
						return 10;
					}).ThenBy(i => i.level).ToList();
					if (source.Any())
					{
						UserShip si = source.First().id.ToUserShip();
						await Runtime.Game.RemoveEquipment(si.id, si.equipmentArr.IndexOf(equip));
						MessagingCenter.Send<LogMessage>(new LogMessage("[换装]移除" + si.Name + "装备:" + equip.ToEquipName()), "Log");
						si = null;
					}
				}
			}
		}

		// Token: 0x06000CA6 RID: 3238 RVA: 0x0006FD50 File Offset: 0x0006DF50
		public static bool CheckFleet(ObservableCollection<RuleFleet> ruleFleet, int fleetID)
		{
			if (!ruleFleet.Any<RuleFleet>())
			{
				return true;
			}
			List<UserShip> list = Runtime.Game.Fleet[fleetID].UserShip.ToList<UserShip>();
			using (IEnumerator<RuleFleet> enumerator = ruleFleet.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					RuleFleet rule = enumerator.Current;
					if (rule.TypeB)
					{
						List<UserShip> list2 = (from i in list
						where rule.ShipType.Contains(i.Type) && i.level >= rule.MinLv && i.level <= rule.MaxLv
						select i).Take(rule.Number).ToList<UserShip>();
						if (list2.Count == rule.Number)
						{
							using (List<UserShip>.Enumerator enumerator2 = list2.GetEnumerator())
							{
								while (enumerator2.MoveNext())
								{
									UserShip item = enumerator2.Current;
									list.Remove(item);
								}
								continue;
							}
						}
						return false;
					}
					if (rule.TypeC)
					{
						List<UserShip> source = (from i in list
						where i.Name.Contains(rule.SelectName) && i.level >= rule.MinLv && i.level <= rule.MaxLv
						select i).ToList<UserShip>();
						if (!source.Any<UserShip>())
						{
							return false;
						}
						list.Remove(source.First<UserShip>());
					}
					else
					{
						List<UserShip> source2 = (from i in list
						where rule.ShipID.Contains(i.id)
						select i).ToList<UserShip>();
						if (!source2.Any<UserShip>())
						{
							return false;
						}
						list.Remove(source2.First<UserShip>());
					}
				}
			}
			return !list.Any<UserShip>();
		}

		// Token: 0x06000CA7 RID: 3239 RVA: 0x0006FEFC File Offset: 0x0006E0FC
		public static void UpdateTactic(this ObservableCollection<Tactic> source, List<Tactic> update)
		{
			try
			{
				if (update != null)
				{
					using (List<Tactic>.Enumerator enumerator = update.GetEnumerator())
					{
						while (enumerator.MoveNext())
						{
							Tactic item = enumerator.Current;
							if (source.Any((Tactic i) => i.boat_id == item.boat_id && i.tactics_id == item.tactics_id))
							{
								Tactic tactic = source.Single((Tactic i) => i.boat_id == item.boat_id && i.tactics_id == item.tactics_id);
								tactic.status = item.status;
								tactic.exp = item.exp;
								tactic.level = item.level;
								tactic.tactics_id = item.tactics_id;
							}
							else
							{
								source.Add(item);
							}
						}
					}
				}
			}
			catch (Exception)
			{
			}
		}

		// Token: 0x06000CA8 RID: 3240 RVA: 0x0006FFE4 File Offset: 0x0006E1E4
		public static void UpdateUserTask(this ObservableCollection<UserQuest> source, List<UserQuest> update)
		{
			try
			{
				if (update != null)
				{
					using (List<UserQuest>.Enumerator enumerator = update.GetEnumerator())
					{
						while (enumerator.MoveNext())
						{
							UserQuest item = enumerator.Current;
							if (source.Any((UserQuest i) => i.taskCid == item.taskCid))
							{
								UserQuest userQuest = source.Single((UserQuest i) => i.taskCid == item.taskCid);
								userQuest.status = item.status;
								userQuest.title = item.title;
								userQuest.type = item.type;
								userQuest.condition = item.condition;
								userQuest.award = item.award;
								userQuest.desc = item.desc;
								userQuest.taskCid = item.taskCid;
								userQuest.userLevel = item.userLevel;
							}
							else
							{
								source.Add(item);
							}
						}
					}
				}
			}
			catch (Exception)
			{
			}
		}

		// Token: 0x06000CA9 RID: 3241 RVA: 0x0007012C File Offset: 0x0006E32C
		public static void UpdateUserPackage(this ObservableCollection<UserItem> source, List<UserItem> update)
		{
			try
			{
				if (update != null)
				{
					using (List<UserItem>.Enumerator enumerator = update.GetEnumerator())
					{
						while (enumerator.MoveNext())
						{
							UserItem item = enumerator.Current;
							if (source.Any((UserItem i) => i.itemCid == item.itemCid))
							{
								source.Single((UserItem i) => i.itemCid == item.itemCid).num = item.num;
							}
							else
							{
								source.Add(item);
							}
						}
					}
				}
			}
			catch (Exception)
			{
			}
		}

		// Token: 0x06000CAA RID: 3242 RVA: 0x000701D8 File Offset: 0x0006E3D8
		public static async void UpdateUserShip(this ObservableCollection<UserShip> source, List<UserShip> update)
		{
			try
			{
				if (update != null)
				{
					using (List<UserShip>.Enumerator enumerator = update.GetEnumerator())
					{
						while (enumerator.MoveNext())
						{
							Extensions.<>c__DisplayClass13_0 CS$<>8__locals1 = new Extensions.<>c__DisplayClass13_0();
							CS$<>8__locals1.item = enumerator.Current;
							if (source.Any((UserShip i) => i.id == CS$<>8__locals1.item.id))
							{
								UserShip userShip = source.Single((UserShip i) => i.id == CS$<>8__locals1.item.id);
								userShip.status = CS$<>8__locals1.item.status;
								userShip.fleetId = CS$<>8__locals1.item.fleetId;
								userShip.isLocked = CS$<>8__locals1.item.isLocked;
								userShip.level = CS$<>8__locals1.item.level;
								userShip.married = CS$<>8__locals1.item.married;
								userShip.battleProps = CS$<>8__locals1.item.battleProps;
								userShip.battlePropsMax = CS$<>8__locals1.item.battlePropsMax;
								userShip.skillLevel = CS$<>8__locals1.item.skillLevel;
								userShip.skillType = CS$<>8__locals1.item.skillType;
								userShip.nextSkillId = CS$<>8__locals1.item.nextSkillId;
								userShip.strengthenAttribute = CS$<>8__locals1.item.strengthenAttribute;
								userShip.equipmentArr = CS$<>8__locals1.item.equipmentArr;
							}
							else
							{
								if (!Runtime.Game.UnlockShip.Contains(CS$<>8__locals1.item.shipCid))
								{
									MessagingCenter.Send<LogMessage>(new LogMessage("[打捞]捞到新船【" + CS$<>8__locals1.item.Name + "】，锁定"), "Log");
									MessagingCenter.Send<LogMessage>(new LogMessage("[打捞]捞到新船【" + CS$<>8__locals1.item.Name + "】，锁定"), "PickLog");
									await Runtime.Remote.LockShip(CS$<>8__locals1.item.id);
									await Runtime.Game.Delay(1000);
									CS$<>8__locals1.item.isLocked = true;
									Runtime.Game.UnlockShip.Add(CS$<>8__locals1.item.shipCid);
								}
								if (!CS$<>8__locals1.item.isLocked && !string.IsNullOrEmpty(Runtime.Game.GlobalConfig.LockWhitelist) && Runtime.Game.GlobalConfig.LockWhitelist.Split(new char[]
								{
									'|'
								}).ToList<string>().Any((string i) => !string.IsNullOrEmpty(i) && CS$<>8__locals1.item.Name.Contains(i)))
								{
									MessagingCenter.Send<LogMessage>(new LogMessage("[打捞]白名单船【" + CS$<>8__locals1.item.Name + "】，锁定"), "Log");
									MessagingCenter.Send<LogMessage>(new LogMessage("[打捞]白名单船【" + CS$<>8__locals1.item.Name + "】，锁定"), "PickLog");
									await Runtime.Remote.LockShip(CS$<>8__locals1.item.id);
									await Runtime.Game.Delay(1000);
									CS$<>8__locals1.item.isLocked = true;
								}
								if (!CS$<>8__locals1.item.isLocked && Runtime.Game.GlobalConfig.LockOne && !Runtime.Game.UserShip.Any((UserShip i) => i.isLocked && i.evoCid == CS$<>8__locals1.item.evoCid))
								{
									MessagingCenter.Send<LogMessage>(new LogMessage("[打捞]唯一船【" + CS$<>8__locals1.item.Name + "】，锁定"), "Log");
									MessagingCenter.Send<LogMessage>(new LogMessage("[打捞]唯一船【" + CS$<>8__locals1.item.Name + "】，锁定"), "PickLog");
									await Runtime.Remote.LockShip(CS$<>8__locals1.item.id);
									await Runtime.Game.Delay(1000);
									CS$<>8__locals1.item.isLocked = true;
								}
								source.Add(CS$<>8__locals1.item);
							}
							CS$<>8__locals1 = null;
						}
					}
					List<UserShip>.Enumerator enumerator = default(List<UserShip>.Enumerator);
				}
			}
			catch (Exception)
			{
			}
		}

		// Token: 0x06000CAB RID: 3243 RVA: 0x0007021C File Offset: 0x0006E41C
		public static void UpdateFleet(this ObservableCollection<UserFleet> source, List<UserFleet> update)
		{
			try
			{
				if (update != null)
				{
					using (List<UserFleet>.Enumerator enumerator = update.GetEnumerator())
					{
						while (enumerator.MoveNext())
						{
							UserFleet item = enumerator.Current;
							if (source.Any((UserFleet i) => i.id == item.id))
							{
								UserFleet userFleet = source.Single((UserFleet i) => i.id == item.id);
								userFleet.ships = item.ships;
								userFleet.status = item.status;
								userFleet.title = item.title;
							}
							else
							{
								source.Add(item);
							}
						}
					}
					foreach (UserShip userShip in Runtime.Game.UserShip)
					{
						userShip.fleetId = 0;
						foreach (UserFleet userFleet2 in Runtime.Game.Fleet)
						{
							if (userFleet2.ships.Contains(userShip.id))
							{
								userShip.fleetId = userFleet2.id;
								break;
							}
						}
					}
					foreach (UserFleet userFleet3 in Runtime.Game.Fleet)
					{
						userFleet3.UpdateShip();
					}
				}
			}
			catch (Exception)
			{
			}
		}

		// Token: 0x06000CAC RID: 3244 RVA: 0x00070410 File Offset: 0x0006E610
		public static void UpdateEquipments(this ObservableCollection<UserEquipment> source, List<UserEquipment> update)
		{
			try
			{
				if (update != null)
				{
					using (List<UserEquipment>.Enumerator enumerator = update.GetEnumerator())
					{
						while (enumerator.MoveNext())
						{
							UserEquipment item = enumerator.Current;
							if (source.Any((UserEquipment i) => i.equipmentCid == item.equipmentCid))
							{
								UserEquipment userEquipment = source.Single((UserEquipment i) => i.equipmentCid == item.equipmentCid);
								userEquipment.locked = item.locked;
								userEquipment.num = item.num;
							}
							else
							{
								source.Add(item);
							}
						}
					}
				}
			}
			catch (Exception)
			{
			}
		}

		// Token: 0x06000CAD RID: 3245 RVA: 0x000704D0 File Offset: 0x0006E6D0
		public static void UpdateUserInfo(this UserInfo source, ResInfo update)
		{
			try
			{
				Runtime.Game.Statistics.oil = Runtime.Game.Statistics.oil + (update.oil - source.oil);
				Runtime.Game.Statistics.steel = Runtime.Game.Statistics.steel + (update.steel - source.steel);
				Runtime.Game.Statistics.ammo = Runtime.Game.Statistics.ammo + (update.ammo - source.ammo);
				Runtime.Game.Statistics.aluminium = Runtime.Game.Statistics.aluminium + (update.aluminium - source.aluminium);
				source.oil = update.oil;
				source.steel = update.steel;
				source.ammo = update.ammo;
				source.aluminium = update.aluminium;
				source.gold = update.gold;
			}
			catch (Exception)
			{
			}
		}

		// Token: 0x06000CAE RID: 3246 RVA: 0x000705E0 File Offset: 0x0006E7E0
		public static UserShip ToUserShip(this int f)
		{
			return Runtime.Game.UserShip.SingleOrDefault((UserShip u) => u.id == f);
		}

		// Token: 0x06000CAF RID: 3247 RVA: 0x00070618 File Offset: 0x0006E818
		public static IEnumerable<UserShip> ToUserShipList(this IList<int> shipID)
		{
			List<UserShip> list = Runtime.Game.UserShip.ToList<UserShip>();
			return from i in shipID
			where list.Any((UserShip s) => s.id == i)
			select i into sid
			select list.First((UserShip i) => i != null && i.id == sid);
		}

		// Token: 0x06000CB0 RID: 3248 RVA: 0x00070664 File Offset: 0x0006E864
		public static IEnumerable<UserShip> ToUserShipList(this int[] shipID)
		{
			List<UserShip> list = Runtime.Game.UserShip.ToList<UserShip>();
			return from i in shipID
			where list.Any((UserShip s) => s.id == i)
			select i into sid
			select list.First((UserShip i) => i != null && i.id == sid);
		}

		// Token: 0x06000CB1 RID: 3249 RVA: 0x000706B0 File Offset: 0x0006E8B0
		public static string ConvertItemName(int itemCid)
		{
			Dictionary<int, string> dictionary = new Dictionary<int, string>
			{
				{
					141,
					"快速建造"
				},
				{
					241,
					"建造蓝图"
				},
				{
					541,
					"快速修理"
				},
				{
					741,
					"装备蓝图"
				},
				{
					10141,
					"航母改造核心"
				},
				{
					10142,
					"港湾的藏品"
				},
				{
					10241,
					"战列改造核心"
				},
				{
					10242,
					"港湾的珍藏"
				},
				{
					10341,
					"巡洋改造核心"
				},
				{
					10441,
					"驱逐改造核心"
				},
				{
					10541,
					"潜艇改造核心"
				},
				{
					66641,
					"损害管理"
				},
				{
					88841,
					"誓约之戒"
				}
			};
			if (dictionary.ContainsKey(itemCid))
			{
				return dictionary[itemCid];
			}
			return "";
		}

		// Token: 0x06000CB2 RID: 3250 RVA: 0x000707AC File Offset: 0x0006E9AC
		public static string ToName(this int shipID)
		{
			UserShip userShip = Runtime.Game.UserShip.SingleOrDefault((UserShip i) => i.id == shipID);
			if (userShip == null)
			{
				return null;
			}
			return userShip.Name;
		}

		// Token: 0x06000CB3 RID: 3251 RVA: 0x000707EC File Offset: 0x0006E9EC
		public static string ToEquipName(this int eID)
		{
			EquipmentConfig equipmentConfig = Runtime.Configs.shipEquipment.SingleOrDefault((EquipmentConfig se) => se.cid == eID);
			if (equipmentConfig == null)
			{
				return null;
			}
			return equipmentConfig.title;
		}

		// Token: 0x06000CB4 RID: 3252 RVA: 0x0007082C File Offset: 0x0006EA2C
		public static string ToName(this ShipType type)
		{
			if (type > (ShipType)30)
			{
				return (new string[]
				{
					"未知",
					"旗舰",
					"其他"
				})[type - ShipType.Unknow];
			}
			return (new string[]
			{
				"",
				"航母",
				"轻母",
				"装母",
				"战列",
				"航战",
				"战巡",
				"重巡",
				"航巡",
				"雷巡",
				"轻巡",
				"重炮",
				"驱逐",
				"潜母",
				"潜艇",
				"炮潜",
				"补给",
				"要塞",
				"机场",
				"港口",
				"商船",
				"登陆",
				"海盗",
				"导驱",
				"防驱"
			})[(int)type];
		}

		// Token: 0x06000CB5 RID: 3253 RVA: 0x00070943 File Offset: 0x0006EB43
		public static string ToName(this ShipBrokenType type)
		{
			return (new string[]
			{
				"",
				"",
				"中破",
				"大破"
			})[(int)type];
		}

		// Token: 0x06000CB6 RID: 3254 RVA: 0x00070970 File Offset: 0x0006EB70
		public static DateTime GetCheckTime(TimeSpan ts, bool tow = false)
		{
			DateTime now = DateTime.Now;
			if (tow)
			{
				return new DateTime(now.Year, now.Month, now.Day, ts.Hours, ts.Minutes, 0).AddDays(1.0);
			}
			if (now > new DateTime(now.Year, now.Month, now.Day, ts.Hours, ts.Minutes, 0))
			{
				return new DateTime(now.Year, now.Month, now.Day, ts.Hours, ts.Minutes, 0).AddDays(1.0);
			}
			return new DateTime(now.Year, now.Month, now.Day, ts.Hours, ts.Minutes, 0);
		}

		// Token: 0x06000CB7 RID: 3255 RVA: 0x00070A56 File Offset: 0x0006EC56
		public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
		{
			HashSet<TKey> hashSet = new HashSet<TKey>();
			foreach (TSource tsource in source)
			{
				if (hashSet.Add(keySelector(tsource)))
				{
					yield return tsource;
				}
			}
			IEnumerator<TSource> enumerator = null;
			yield break;
			yield break;
		}

		// Token: 0x06000CB8 RID: 3256 RVA: 0x00070A70 File Offset: 0x0006EC70
		public static int FindIndex<T>(this IEnumerable<T> items, Func<T, bool> predicate)
		{
			if (items == null)
			{
				throw new ArgumentNullException("items");
			}
			if (predicate == null)
			{
				throw new ArgumentNullException("predicate");
			}
			int num = 0;
			foreach (T arg in items)
			{
				if (predicate(arg))
				{
					return num;
				}
				num++;
			}
			return -1;
		}

		// Token: 0x06000CB9 RID: 3257 RVA: 0x00070AE4 File Offset: 0x0006ECE4
		public static int IndexOf<T>(this IEnumerable<T> items, T item)
		{
			return items.FindIndex((T i) => EqualityComparer<T>.Default.Equals(item, i));
		}

		// Token: 0x02000214 RID: 532
		public class TargetFleet
		{
			// Token: 0x170003F2 RID: 1010
			// (get) Token: 0x06000CBA RID: 3258 RVA: 0x00070B10 File Offset: 0x0006ED10
			// (set) Token: 0x06000CBB RID: 3259 RVA: 0x00070B18 File Offset: 0x0006ED18
			public int ID { get; set; }

			// Token: 0x170003F3 RID: 1011
			// (get) Token: 0x06000CBC RID: 3260 RVA: 0x00070B21 File Offset: 0x0006ED21
			// (set) Token: 0x06000CBD RID: 3261 RVA: 0x00070B29 File Offset: 0x0006ED29
			public RuleFleet RuleFleet { get; set; }
		}
	}
}
